package com.kainitram.undo;

import com.kainitram.designpattern.Command;

/**
 * Invoker for undo redo commands
 * 
 * @author Mino
 * 
 */
public class UndoRedoInvoker implements IUndoRedoInvoker {

	private IUndoRedoCommand lastCommand;

	public Boolean invoke(Command command) {
		Boolean ret = false;

		if (command.canExecute()) {
			ret = true;
			command.execute();
			lastCommand = (IUndoRedoCommand) command;
		}

		return ret;
	}

	public void undo() {
		if (canUndo()) {
			lastCommand.undo();
			lastCommand = null;
		}
	}

	public void redo() {

	}

	public Boolean canUndo() {
		return lastCommand != null;
	}

	public Boolean canRedo() {
		return false;
	}

}
